<?php namespace App\Http\Controllers;

use App\AboutUs;
use App\Achievement;
use App\Admin;
use App\ApplicationField;
use App\Banner;
use App\BooksChapter;
use App\BooksInfo;
use App\CharitableActivities;
use App\Classify;
use App\Comment;
use App\EnAboutUs;
use App\EnAchievement;
use App\EnApplicationField;
use App\EnBanner;
use App\EnCharitableActivities;
use App\EnComment;
use App\EnEnvironmentalProtectionKnowledge;
use App\EnFooterMenu;
use App\EnGoodsProduct;
use App\EnHumanResources;
use App\EnNews;
use App\EnPhilanthropy;
use App\EnProjectCases;
use App\EnSysInfo;
use App\EnvironmentalProtectionKnowledge;
use App\FooterMenu;
use App\GoodsProduct;
use App\Http\Controllers\Api\AudioController;
use App\Http\Services\FileManager;
use App\HumanResources;
use App\News;
use App\OnlineMessage;
use App\Philanthropy;
use App\ProjectCases;
use App\SysInfo;
use App\UserVip;
use App\VipRule;
use App\VolunteerApply;
use Blocktrail\CryptoJSAES\CryptoJSAES;
use App\RechargePackage;
use App\User;
use App\UserInfo;
use App\UserSpendRecord;
use Illuminate\Contracts\Auth\Guard;
use DB;
use Auth;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\File;

class AdminController extends Controller
{
    public function login()
    {
        return view('admin.login');
    }

    public function bannerList()
    {
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $type = 'banner';

        /** @var Banner $sysBanner */
        $sysBanners = Banner::orderBy('sort', 'asc')->orderBy('created_at', 'desc')->get();
        if (count($sysBanners) > 0) {
            foreach ($sysBanners as $sysBanner) {
                $sysBanner->img_url = FileManager::getImgUrl($sysBanner->img_id);
            }
        }

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.banner-list', ['banners' => $sysBanners,'type' => $type,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    public function bannerSet(Request $request)
    {
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $type = 'banner';

        $id = !is_null($request->get('id')) ? $request->get('id') : 0;

        /** @var Banner $thatBanner */
        $thatBanner = Banner::whereId($id)->first();
        if ($thatBanner) {
            $thatBanner->img_url = FileManager::getImgUrl($thatBanner->img_id);
        }

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.banner-set', ['banner' => $thatBanner,'type' => $type,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    public function userList(Request $request)
    {
        if (Auth::guard("admin")->guest())
            return response()->json(['level' => 'error', 'message' => '请先登录！']);

        $users = User::orderBy("created_at", "desc")->paginate(50);

        foreach ($users as $user) {
            /** @var User $user */
            $user->userInfo;
            $user->userInfo->photo_url = FileManager::getImgUrl($user->userInfo->photo_id);
        }

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.user-list', ["users" => $users,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    public function adminList(Request $request)
    {
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        /** @var Admin $newAdmin */
        $newAdmins = Admin::orderBy('created_at', 'desc')->paginate(10);

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.admin-list', ['admins' => $newAdmins,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    public function adminSet(Request $request)
    {
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.admin-set',['zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    public function changePwd()
    {
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.change-psw',['zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    public function classifyList(Request $request)
    {
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $languageType = "zh";

        /** @var Classify $class */
        $classify = Classify::whereLanguageType($languageType)->orderBy('sort', 'asc')->orderBy('created_at', 'desc')->get();
        if(count($classify) > 0){
            foreach($classify as $class){
                $class->img_url = FileManager::getImgUrl($class->img_id);
            }
        }

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.classify-list', ['classify' => $classify,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    public function enClassifyList(Request $request){
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $languageType = "en";

        $classify = Classify::whereLanguageType($languageType)->orderBy('sort', 'asc')->orderBy('created_at', 'desc')->get();
        if(count($classify) > 0){
            foreach($classify as $class){
                $class->img_url = FileManager::getImgUrl($class->img_id);
            }
        }

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.classify-list', ['classify' => $classify,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    public function webSiteInfo(Request $request)
    {
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        /** @var SysInfo $sysInfo */
        $allSysInfo = SysInfo::all();

        $webInfoArr = null;
        if (count($allSysInfo) > 0) {
            foreach ($allSysInfo as $sysInfo) {
                switch ($sysInfo->type) {
                    case 'title':
                        $webInfoArr['title'] = $sysInfo->content;
                        break;
                    case 'desc':
                        $webInfoArr['desc'] = $sysInfo->content;
                        break;
                    case 'keyword':
                        $webInfoArr['keyword'] = $sysInfo->content;
                        break;
                    case 'logo':
                        $webInfoArr['logo_url'] = FileManager::getImgUrl((int)$sysInfo->content);
                        break;
                    case 'url':
                        $webInfoArr['url'] = $sysInfo->content;
                        break;
                    case 'footer':
                        $webInfoArr['footer_info'] = $sysInfo->content;
                        break;
                    case 'record':
                        $webInfoArr['record'] = $sysInfo->content;
                        break;
                }
            }
        }

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.website-info', ['webInfoArr' => $webInfoArr,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    public function footerMenu(Request $request)
    {
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        /** @var FooterMenu $footerMenu */
        $allFooterMenu = FooterMenu::wherePid(0)->orderBy('sort','asc')->orderBy('created_at','desc')->get();

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.footer-info', ['allFooterMenu' => $allFooterMenu,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    public function footerMenuChild(Request $request){
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $id = !is_null($request->get('id')) ? $request->get('id') : 0;

        $footerMenuChild = FooterMenu::wherePid($id)->orderBy('sort','asc')->orderBy('created_at','desc')->get();

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.footer-info-child',['footerMenuChild' => $footerMenuChild,'pid' => $id,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    //我们的成就
    public function achievementList(Request $request){
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $type = 'achievement';

        /** @var Achievement $applicationField */
        $applicationFieldList = Achievement::orderBy('sort', 'asc')->orderBy('created_at','desc')->get();
        if(count($applicationFieldList) > 0){
            foreach($applicationFieldList as $applicationField){
                $applicationField->img_url       = FileManager::getImgUrl($applicationField->img_id);
            }
        }

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.achievement-list', ['type' => $type,'applicationFieldList' => $applicationFieldList,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    //我们的成就详情
    public function achievementSet(Request $request){
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $type = 'achievement';

        $id = !is_null($request->get('id')) ? $request->get('id') : 0;

        $applicationField = Achievement::whereId($id)->first();
        if($applicationField){
            $applicationField->img_url = FileManager::getImgUrl($applicationField->img_id);
        }

        $section = (object)[];
        $section->classify_name = '';
        $section->classify_desc = '';

        $classify = Classify::whereType($type)->first();
        if($classify){
            $section->classify_name = $classify->name;
            $section->classify_desc = $classify->desc;
        }

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.achievement-set',['type' => $type,'applicationField' => $applicationField,'section' => $section,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    //英文-我们的成就
    public function enAchievementList(Request $request){
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $type = 'en_achievement';

        /** @var Achievement $applicationField */
        $applicationFieldList = EnAchievement::orderBy('sort', 'asc')->orderBy('created_at','desc')->get();
        if(count($applicationFieldList) > 0){
            foreach($applicationFieldList as $applicationField){
                $applicationField->img_url       = FileManager::getImgUrl($applicationField->img_id);
            }
        }

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.achievement-list', ['type' => $type,'applicationFieldList' => $applicationFieldList,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    //英文-我们的成就详情
    public function enAchievementSet(Request $request){
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $type = 'en_achievement';

        $id = !is_null($request->get('id')) ? $request->get('id') : 0;

        $applicationField = EnAchievement::whereId($id)->first();
        if($applicationField){
            $applicationField->img_url = FileManager::getImgUrl($applicationField->img_id);
        }

        $section = (object)[];
        $section->classify_name = '';
        $section->classify_desc = '';

        $classify = Classify::whereType($type)->first();
        if($classify){
            $section->classify_name = $classify->name;
            $section->classify_desc = $classify->desc;
        }

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.achievement-set',['type' => $type,'applicationField' => $applicationField,'section' => $section,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    //公益理念
    public function philanthropyList(Request $request)
    {
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $type = 'philanthropy';

        /** @var Philanthropy $philanthropy */
        $goodsProductList = Philanthropy::orderBy('sort', 'asc')->orderBy('created_at', 'desc')->paginate(20);
        if (count($goodsProductList) > 0) {
            foreach ($goodsProductList as $philanthropy) {
                $philanthropy->img_url = FileManager::getImgUrl($philanthropy->img_id);
            }
        }

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.philanthropy-list', ['goodsProductList' => $goodsProductList,'type' => $type,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    //公益理念详情
    public function philanthropySet(Request $request)
    {
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $type = 'philanthropy';

        $id = !is_null($request->get('id')) ? $request->get('id') : 0;

        $sysGoods = Philanthropy::whereId($id)->first();
        if($sysGoods){
            $sysGoods->img_url       = FileManager::getImgUrl($sysGoods->img_id);
            $sysGoods->thumb_img_url = FileManager::getImgUrl($sysGoods->thumb_img_id);
        }

        $section = (object)[];
        $section->classify_name = '';
        $section->classify_desc = '';

        $classify = Classify::whereType($type)->first();
        if($classify){
            $section->classify_name = $classify->name;
            $section->classify_desc = $classify->desc;
        }

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.philanthropy-set', ['sysGoods' => $sysGoods,'type' => $type,'section' => $section,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    //最新动态
    public function newsList()
    {
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $type = 'news';

        /** @var News $news */
        $newsList = News::orderBy('sort', 'asc')->orderBy('created_at', 'desc')->paginate(20);
        if (count($newsList) > 0) {
            foreach ($newsList as $news) {
                $news->img_url  = FileManager::getImgUrl($news->img_id);
                $news->link_url = env('HOST_URL') . '/news-detail?id=' . $news->id;
            }
        }

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.news-list',['newsList' => $newsList,'type' => $type,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    //最新动态详情
    public function newsSet(Request $request){
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $type = 'news';

        $id = !is_null($request->get('id')) ? $request->get('id') : 0;

        $thisNews = News::whereId($id)->first();
        if($thisNews){
            $thisNews->img_url = FileManager::getImgUrl($thisNews->img_id);
            $thisNews->thumb_img_url = FileManager::getImgUrl($thisNews->thumb_img_id);
        }

        $section = (object)[];
        $section->classify_name = '';
        $section->classify_desc = '';

        $classify = Classify::whereType($type)->first();
        if($classify){
            $section->classify_name = $classify->name;
            $section->classify_desc = $classify->desc;
        }

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.news-set',['thisNews' => $thisNews,'type' => $type,'section' => $section,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    //项目案例
    public function projectCaseList()
    {
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $type = 'project_case';

        /** @var News $news */
        $newsList = ProjectCases::orderBy('sort', 'asc')->orderBy('created_at', 'desc')->paginate(20);
        if (count($newsList) > 0) {
            foreach ($newsList as $news) {
                $news->img_url  = FileManager::getImgUrl($news->img_id);
                $news->link_url = env('HOST_URL') . '/project-case-detail?id=' . $news->id;
            }
        }

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.project-case-list',['newsList' => $newsList,'type' => $type,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    //项目案例详情
    public function projectCaseSet(Request $request){
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $type = 'project_case';

        $id = !is_null($request->get('id')) ? $request->get('id') : 0;

        $thisNews = ProjectCases::whereId($id)->first();
        if($thisNews){
            $thisNews->img_url = FileManager::getImgUrl($thisNews->img_id);
            $thisNews->thumb_img_url = FileManager::getImgUrl($thisNews->thumb_img_id);
        }

        $section = (object)[];
        $section->classify_name = '';
        $section->classify_desc = '';

        $classify = Classify::whereType($type)->first();
        if($classify){
            $section->classify_name = $classify->name;
            $section->classify_desc = $classify->desc;
        }

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.project-case-set',['thisNews' => $thisNews,'type' => $type,'section' => $section,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    //英文-项目案例
    public function enProjectCaseList()
    {
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $type = 'en_project_case';

        /** @var News $news */
        $newsList = EnProjectCases::orderBy('sort', 'asc')->orderBy('created_at', 'desc')->paginate(20);
        if (count($newsList) > 0) {
            foreach ($newsList as $news) {
                $news->img_url = FileManager::getImgUrl($news->img_id);
                $news->link_url = env('HOST_URL') . '/en/en-project-case-detail?id=' . $news->id;
            }
        }

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.project-case-list',['newsList' => $newsList,'type' => $type,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    //英文-项目案例详情
    public function enProjectCaseSet(Request $request){
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $type = 'en_project_case';

        $id = !is_null($request->get('id')) ? $request->get('id') : 0;

        $thisNews = EnProjectCases::whereId($id)->first();
        if($thisNews){
            $thisNews->img_url = FileManager::getImgUrl($thisNews->img_id);
            $thisNews->thumb_img_url = FileManager::getImgUrl($thisNews->thumb_img_id);
        }

        $section = (object)[];
        $section->classify_name = '';
        $section->classify_desc = '';

        $classify = Classify::whereType($type)->first();
        if($classify){
            $section->classify_name = $classify->name;
            $section->classify_desc = $classify->desc;
        }

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.project-case-set',['thisNews' => $thisNews,'type' => $type,'section' => $section,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    //环保知识
    public function environmentalList()
    {
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $type = 'environmental';

        /** @var EnvironmentalProtectionKnowledge $news */
        $newsList = EnvironmentalProtectionKnowledge::orderBy('sort', 'asc')->orderBy('created_at', 'desc')->paginate(20);
        if (count($newsList) > 0) {
            foreach ($newsList as $news) {
                $news->img_url = FileManager::getImgUrl($news->img_id);
                $news->link_url = env('HOST_URL') . '/environmental-detail?id=' . $news->id;

                /** @var Classify $thisClassify */
                $thisClassify = Classify::whereId($news->classify_two_id)->first();
                if($thisClassify){
                    $news->classify_name = $thisClassify->name;
                }else{
                    $news->classify_name = null;
                }
            }
        }

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.environmental-list',['newsList' => $newsList,'type' => $type,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    //环保知识详情
    public function environmentalSet(Request $request){
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $type = 'environmental';

        $id = !is_null($request->get('id')) ? $request->get('id') : 0;

        $thisNews = EnvironmentalProtectionKnowledge::whereId($id)->first();
        if($thisNews){
            $thisNews->img_url = FileManager::getImgUrl($thisNews->img_id);
            $thisNews->thumb_img_url = FileManager::getImgUrl($thisNews->thumb_img_id);
        }

        $section = (object)[];
        $section->classify_name = '';
        $section->classify_desc = '';

        $classify = Classify::whereType('environmental_section')->first();
        if($classify){
            $section->classify_name = $classify->name;
            $section->classify_desc = $classify->desc;
        }

        $classifies = Classify::whereType('environmental')->get();

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.environmental-set',['thisNews' => $thisNews,'classifies' => $classifies,'type' => $type,'section' => $section,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    //英文-环保知识
    public function enEnvironmentalList()
    {
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $type = 'en_environmental';

        /** @var EnEnvironmentalProtectionKnowledge $news */
        $newsList = EnEnvironmentalProtectionKnowledge::orderBy('sort', 'asc')->orderBy('created_at', 'desc')->paginate(20);
        if (count($newsList) > 0) {
            foreach ($newsList as $news) {
                $news->img_url = FileManager::getImgUrl($news->img_id);
                $news->link_url = env('HOST_URL') . '/en/en-environmental-detail?id=' . $news->id;

                /** @var Classify $thisClassify */
                $thisClassify = Classify::whereId($news->classify_two_id)->first();
                if($thisClassify){
                    $news->classify_name = $thisClassify->name;
                }else{
                    $news->classify_name = null;
                }
            }
        }

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.environmental-list',['newsList' => $newsList,'type' => $type,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    //英文-环保知识详情
    public function enEnvironmentalSet(Request $request){
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $type = 'en_environmental';

        $id = !is_null($request->get('id')) ? $request->get('id') : 0;

        $thisNews = EnEnvironmentalProtectionKnowledge::whereId($id)->first();
        if($thisNews){
            $thisNews->img_url = FileManager::getImgUrl($thisNews->img_id);
            $thisNews->thumb_img_url = FileManager::getImgUrl($thisNews->thumb_img_id);
        }

        $section = (object)[];
        $section->classify_name = '';
        $section->classify_desc = '';

        $classify = Classify::whereType('en_environmental_section')->first();
        if($classify){
            $section->classify_name = $classify->name;
            $section->classify_desc = $classify->desc;
        }

        $classifies = Classify::whereType('en_environmental')->get();

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.environmental-set',['thisNews' => $thisNews,'classifies' => $classifies,'type' => $type,'section' => $section,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    //环保知识分类
    public function environmentalClassifyList(Request $request){
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $type = 'environmental';

        $allClassifies = Classify::whereType($type)->orderBy('sort', 'asc')->orderBy('created_at', 'desc')->get();
        if(count($allClassifies) > 0){
            foreach($allClassifies as $allClassify){
                $allClassify->link_url = env('HOST_URL') . '/environmental-list?classify_id=' . $allClassify->id;
            }
        }

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.all-classify-list', ['type' => $type, 'allClassifies' => $allClassifies,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    //英文-环保知识分类
    public function enEnvironmentalClassifyList(Request $request){
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $type = 'en_environmental';

        $allClassifies = Classify::whereType($type)->orderBy('sort', 'asc')->orderBy('created_at', 'desc')->get();
        if(count($allClassifies) > 0){
            foreach($allClassifies as $allClassify){
                $allClassify->link_url = env('HOST_URL') . '/en/en-environmental-list?classify_id=' . $allClassify->id;
            }
        }

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.all-classify-list', ['type' => $type, 'allClassifies' => $allClassifies,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    //关于我们
    public function aboutUsList(Request $request){
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $type = 'about_us';

        /** @var AboutUs $aboutUs */
        $aboutUsList = AboutUs::orderBy('sort', 'asc')->orderBy('created_at','desc')->get();
        if(count($aboutUsList) > 0){
            foreach($aboutUsList as $aboutUs){
                $aboutUs->img_url = FileManager::getImgUrl($aboutUs->img_id);
                $aboutUs->link_url = env('HOST_URL') . '/about-detail?id=' . $aboutUs->id;

                /** @var Classify $thisClassify */
                $thisClassify = Classify::whereId($aboutUs->classify_id)->first();
                if($thisClassify){
                    $aboutUs->classify_name = $thisClassify->name;
                }else{
                    $aboutUs->classify_name = null;
                }
            }
        }

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.about-us-list',['aboutUsList' => $aboutUsList,'type' => $type,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    //关于我们详情
    public function aboutUsSet(Request $request){
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $type = 'about_us';

        $id = !is_null($request->get('id')) ? $request->get('id') : 0;

        $thisAboutUs = AboutUs::whereId($id)->first();
        if($thisAboutUs){
            $thisAboutUs->img_url = FileManager::getImgUrl($thisAboutUs->img_id);
            $thisAboutUs->thumb_img_url = FileManager::getImgUrl($thisAboutUs->thumb_img_id);
        }

        $classifies = Classify::whereType('about_us')->get();

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.about-us-set',['type' => $type,'thisAboutUs' => $thisAboutUs,'classifies' => $classifies,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    public function aboutUsClassifyList(Request $request){
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $type = 'about_us';

        $allClassifies = Classify::whereType($type)->orderBy('sort', 'asc')->orderBy('created_at', 'desc')->get();

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.all-classify-list', ['type' => $type, 'allClassifies' => $allClassifies,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    public function commentList(Request $request){
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $type = 'comment';

        /** @var Comment $HumanRes */
        $HumanResList = Comment::orderBy('sort', 'asc')->orderBy('created_at','desc')->get();
        if(count($HumanResList) > 0){
            foreach($HumanResList as $HumanRes){
                $HumanRes->photo_url = FileManager::getImgUrl($HumanRes->photo_id);
            }
        }

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.comment-list',['type' => $type,'HumanResList' => $HumanResList,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    public function commentSet(Request $request){
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $type = 'comment';

        $id = !is_null($request->get('id')) ? $request->get('id') : 0;

        $thisHumanRes = Comment::whereId($id)->first();
        if($thisHumanRes){
            $thisHumanRes->photo_url = FileManager::getImgUrl($thisHumanRes->photo_id);
        }

        $section = (object)[];
        $section->classify_name = '';
        $section->classify_desc = '';

        $classify = Classify::whereType($type)->first();
        if($classify){
            $section->classify_name = $classify->name;
            $section->classify_desc = $classify->desc;
        }

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.comment-set',['type' => $type,'thisHumanRes' => $thisHumanRes,'section' => $section,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    public function enCommentList(Request $request){
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $type = 'en_comment';

        /** @var EnComment $HumanRes */
        $HumanResList = EnComment::orderBy('sort', 'asc')->orderBy('created_at','desc')->get();
        if(count($HumanResList) > 0){
            foreach($HumanResList as $HumanRes){
                $HumanRes->photo_url = FileManager::getImgUrl($HumanRes->photo_id);
            }
        }

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.comment-list',['HumanResList' => $HumanResList,'type' => $type,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    public function enCommentSet(Request $request){
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $type = 'en_comment';

        $id = !is_null($request->get('id')) ? $request->get('id') : 0;

        $thisHumanRes = EnComment::whereId($id)->first();
        if($thisHumanRes){
            $thisHumanRes->photo_url = FileManager::getImgUrl($thisHumanRes->photo_id);
        }

        $section = (object)[];
        $section->classify_name = '';
        $section->classify_desc = '';

        $classify = Classify::whereType($type)->first();
        if($classify){
            $section->classify_name = $classify->name;
            $section->classify_desc = $classify->desc;
        }

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.comment-set',['type' => $type,'thisHumanRes' => $thisHumanRes,'section' => $section,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    //招募
    public function volunteerList(Request $request){
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $volunteerList = VolunteerApply::orderBy('created_at', 'desc')->paginate(20);
        if (count($volunteerList) > 0) {
            foreach($volunteerList as $volunteer) {
                if($volunteer->sex == 0){
                    $volunteer->sex_name = '保密';
                }elseif($volunteer->sex == 1){
                    $volunteer->sex_name = '男';
                }elseif($volunteer->sex == 2){
                    $volunteer->sex_name = '女';
                }else{
                    $volunteer->sex_name = '未知';
                }
            }
        }

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.volunteer-list',['volunteerList' => $volunteerList,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    //留言
    public function onlineMessageList(Request $request){
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $volunteerList = OnlineMessage::orderBy('created_at', 'desc')->paginate(20);

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.online-message-list',['volunteerList' => $volunteerList,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    //公益活动
    public function charitableList()
    {
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $type = 'charitable';

        /** @var News $news */
        $newsList = CharitableActivities::orderBy('sort', 'asc')->orderBy('created_at', 'desc')->paginate(20);
        if (count($newsList) > 0) {
            foreach ($newsList as $news) {
                $news->img_url = FileManager::getImgUrl($news->img_id);
                $news->link_url = env('HOST_URL') . '/charitable-detail?id=' . $news->id;
            }
        }

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.charitable-list',['newsList' => $newsList,'type' => $type,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    //公益活动详情
    public function charitableSet(Request $request){
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $type = 'charitable';

        $id = !is_null($request->get('id')) ? $request->get('id') : 0;

        $thisNews = CharitableActivities::whereId($id)->first();
        if($thisNews){
            $thisNews->img_url = FileManager::getImgUrl($thisNews->img_id);
            $thisNews->thumb_img_url = FileManager::getImgUrl($thisNews->thumb_img_id);
        }

        $section = (object)[];
        $section->classify_name = '';
        $section->classify_desc = '';

        $classify = Classify::whereType($type)->first();
        if($classify){
            $section->classify_name = $classify->name;
            $section->classify_desc = $classify->desc;
        }

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.charitable-set',['thisNews' => $thisNews,'type' => $type,'section' => $section,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    //英文-公益活动
    public function enCharitableList()
    {
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $type = 'en_charitable';

        /** @var News $news */
        $newsList = EnCharitableActivities::orderBy('sort', 'asc')->orderBy('created_at', 'desc')->paginate(20);
        if (count($newsList) > 0) {
            foreach ($newsList as $news) {
                $news->img_url = FileManager::getImgUrl($news->img_id);
                $news->link_url = env('HOST_URL') . '/en/en-charitable-detail?id=' . $news->id;
            }
        }

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.charitable-list',['newsList' => $newsList,'type' => $type,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    //英文-公益活动详情
    public function enCharitableSet(Request $request){
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $type = 'en_charitable';

        $id = !is_null($request->get('id')) ? $request->get('id') : 0;

        $thisNews = EnCharitableActivities::whereId($id)->first();
        if($thisNews){
            $thisNews->img_url = FileManager::getImgUrl($thisNews->img_id);
            $thisNews->thumb_img_url = FileManager::getImgUrl($thisNews->thumb_img_id);
        }

        $section = (object)[];
        $section->classify_name = '';
        $section->classify_desc = '';

        $classify = Classify::whereType($type)->first();
        if($classify){
            $section->classify_name = $classify->name;
            $section->classify_desc = $classify->desc;
        }

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.charitable-set',['thisNews' => $thisNews,'type' => $type,'section' => $section,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    public function enWebSiteInfo(Request $request){
        if(Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        /** @var EnSysInfo $enSysInfo */
        $enSysInfos = EnSysInfo::all();

        $webInfoArr = null;
        if(count($enSysInfos) > 0){
            foreach($enSysInfos as $enSysInfo){
                switch ($enSysInfo->type) {
                    case 'title':
                        $webInfoArr['title'] = $enSysInfo->content;
                        break;
                    case 'desc':
                        $webInfoArr['desc'] = $enSysInfo->content;
                        break;
                    case 'keyword':
                        $webInfoArr['keyword'] = $enSysInfo->content;
                        break;
                    case 'logo':
                        $webInfoArr['logo_url'] = FileManager::getImgUrl((int)$enSysInfo->content);
                        break;
                    case 'url':
                        $webInfoArr['url'] = $enSysInfo->content;
                        break;
                    case 'footer':
                        $webInfoArr['footer_info'] = $enSysInfo->content;
                        break;
                    case 'record':
                        $webInfoArr['record'] = $enSysInfo->content;
                        break;
                }
            }
        }

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.en-website-info',['webInfoArr' => $webInfoArr,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    public function enFooterMenu(){
        if(Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        /** @var EnFooterMenu $footerMenu */
        $allEnFooterMenu = EnFooterMenu::wherePid(0)->orderBy('sort','asc')->orderBy('created_at','desc')->get();

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.en-footer-info',['allEnFooterMenu' => $allEnFooterMenu,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    public function enFooterMenuChild(Request $request){
        if(Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $id = !is_null($request->get('id')) ? $request->get('id') : 0;

        $footerMenuChild = EnFooterMenu::wherePid($id)->orderBy('sort','asc')->orderBy('created_at','desc')->get();

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.en-footer-info-child',['footerMenuChild' => $footerMenuChild,'pid' => $id,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    //英文-公益理念
    public function enPhilanthropyList(Request $request){
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $type = 'en_philanthropy';

        /** @var EnPhilanthropy $goodsProduct */
        $goodsProductList = EnPhilanthropy::orderBy('sort', 'asc')->orderBy('created_at', 'desc')->paginate(20);
        if (count($goodsProductList) > 0) {
            foreach ($goodsProductList as $goodsProduct) {
                $goodsProduct->img_url = FileManager::getImgUrl($goodsProduct->img_id);
            }
        }

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.philanthropy-list', ['goodsProductList' => $goodsProductList,'type' => $type,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    //英文-公益理念详情
    public function enPhilanthropySet(Request $request){
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $type = 'en_philanthropy';

        $id = !is_null($request->get('id')) ? $request->get('id') : 0;

        $sysGoods = EnPhilanthropy::whereId($id)->first();
        if($sysGoods){
            $sysGoods->img_url = FileManager::getImgUrl($sysGoods->img_id);
        }

        $section = (object)[];
        $section->classify_name = '';
        $section->classify_desc = '';

        $classify = Classify::whereType($type)->first();
        if($classify){
            $section->classify_name = $classify->name;
            $section->classify_desc = $classify->desc;
        }

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.philanthropy-set', ['sysGoods' => $sysGoods,'type' => $type,'section' => $section,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    //英文-最新动态
    public function enNewsList()
    {
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $type = 'en_news';

        /** @var EnNews $news */
        $newsList = EnNews::orderBy('sort', 'asc')->orderBy('created_at', 'desc')->paginate(20);
        if (count($newsList) > 0) {
            foreach ($newsList as $news) {
                $news->img_url = FileManager::getImgUrl($news->img_id);
                $news->link_url = env('HOST_URL') . '/en/en-news-detail?id=' . $news->id;

            }
        }

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.news-list',['newsList' => $newsList,'type' => $type,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    //英文-最新动态详情
    public function enNewsSet(Request $request){
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $type = 'en_news';

        $id = !is_null($request->get('id')) ? $request->get('id') : 0;

        $thisNews = EnNews::whereId($id)->first();
        if($thisNews){
            $thisNews->img_url = FileManager::getImgUrl($thisNews->img_id);
            $thisNews->thumb_img_url = FileManager::getImgUrl($thisNews->thumb_img_id);
        }

        $section = (object)[];
        $section->classify_name = '';
        $section->classify_desc = '';

        $classify = Classify::whereType($type)->first();
        if($classify){
            $section->classify_name = $classify->name;
            $section->classify_desc = $classify->desc;
        }

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.news-set',['thisNews' => $thisNews,'type' => $type,'section' => $section,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    public function enAboutUsList(Request $request){
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $type = 'en_about_us';

        /** @var EnAboutUs $aboutUs */
        $aboutUsList = EnAboutUs::orderBy('sort', 'asc')->orderBy('created_at','desc')->get();
        if(count($aboutUsList) > 0){
            foreach($aboutUsList as $aboutUs){
                $aboutUs->img_url = FileManager::getImgUrl($aboutUs->img_id);
                $aboutUs->link_url = env('HOST_URL') . '/en/en-about-detail?id=' . $aboutUs->id;

                /** @var Classify $thisClassify */
                $thisClassify = Classify::whereId($aboutUs->classify_id)->first();
                if($thisClassify){
                    $aboutUs->classify_name = $thisClassify->name;
                }else{
                    $aboutUs->classify_name = null;
                }
            }
        }

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.about-us-list',['aboutUsList' => $aboutUsList,'type' => $type,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    public function enAboutUsSet(Request $request){
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $type = 'en_about_us';

        $id = !is_null($request->get('id')) ? $request->get('id') : 0;

        $thisAboutUs = EnAboutUs::whereId($id)->first();
        if($thisAboutUs){
            $thisAboutUs->img_url = FileManager::getImgUrl($thisAboutUs->img_id);
            $thisAboutUs->thumb_img_url = FileManager::getImgUrl($thisAboutUs->thumb_img_id);
        }

        $classifies = Classify::whereType($type)->get();

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.about-us-set',['type' => $type,'thisAboutUs' => $thisAboutUs,'classifies' => $classifies,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    public function enAboutUsClassifyList(Request $request){
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $type = 'en_about_us';

        $allClassifies = Classify::whereType($type)->orderBy('sort', 'asc')->orderBy('created_at', 'desc')->get();

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.all-classify-list', ['type' => $type, 'allClassifies' => $allClassifies,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    public function enBannerList()
    {
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $type = 'en_banner';

        /** @var EnBanner $sysBanner */
        $sysBanners = EnBanner::orderBy('sort', 'asc')->orderBy('created_at', 'desc')->get();
        if (count($sysBanners) > 0) {
            foreach ($sysBanners as $sysBanner) {
                $sysBanner->img_url = FileManager::getImgUrl($sysBanner->img_id);
            }
        }

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.banner-list', ['banners' => $sysBanners,'type' => $type,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }

    public function enBannerSet(Request $request)
    {
        if (Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $type = 'en_banner';
        $id   = !is_null($request->get('id')) ? $request->get('id') : 0;

        /** @var EnBanner $thatBanner */
        $thatBanner = EnBanner::whereId($id)->first();
        if ($thatBanner) {
            $thatBanner->img_url = FileManager::getImgUrl($thatBanner->img_id);
        }

        $zhClassify = Classify::whereLanguageType('zh')->get();

        $enClassify = Classify::whereLanguageType('en')->get();

        return view('admin.banner-set', ['banner' => $thatBanner,'type' => $type,'zhClassify' => $zhClassify,'enClassify' => $enClassify]);
    }
}